package Tracker.server.model;

import java.util.Enumeration;
import java.util.Hashtable;

public class Model {
	int idCounter;
	int sessionCounter;
	Hashtable<Integer, Track> tracks;
	Hashtable<Integer, User> users;
	Hashtable<String, User> userNames;
	Hashtable<Integer, Session> sessions;
	
	public Model() {
		this.tracks = new Hashtable<Integer, Track>();
		this.users = new Hashtable<Integer, User>();
		this.userNames = new Hashtable<String, User>();
		this.idCounter = 0;
		
		this.sessions = new Hashtable<Integer, Session>();
		this.sessionCounter = 0;
	}
	
	public int getUID() {
		this.idCounter++;
		return this.idCounter;
	}
	
	public int getSID() {
		this.sessionCounter++;
		return this.sessionCounter;
	}
	
	public void addTrack(Track t) {
		this.tracks.put(t.id, t);
	}
	
	public boolean  containsTrack(int id) {
		return this.tracks.containsKey(id);
	}
	
	public Track getTrack(Integer id) {
		return this.tracks.get(id);
	}
	
	public Enumeration<Integer> getTrackIterator() {
		return this.tracks.keys();
	}
	
	public void removeTrack(Integer id) {
		this.tracks.remove(id);
	}
	
	public void addUser(User u) {
		this.users.put(u.id, u);
		this.userNames.put(u.name, u);
	}
	
	public User getUserById(Integer id) {
		return this.users.get(id);
	}
	
	public User getUserByName(String n) {
		return this.userNames.get(n);
	}
	
	public boolean  containsUser(String n) {
		return this.userNames.containsKey(n);
	}
	
	public void removeUser(Integer id) {
		this.users.remove(id);
	}
	
	public void addSession(Session s) {
		this.sessions.put(s.id, s);
	}
	
	public boolean containsSession(int id) {
		return this.sessions.containsKey(id);
	}
	
	public Session getSession(Integer id) {
		return this.sessions.get(id);
	}
	
	public void removeSession(Integer id) {
		this.sessions.remove(id);
	}
}
